package com.xigua.nio;

import java.nio.IntBuffer;

/**
 * 举例说明buffer的使用
 */
public class BasicBuffer {
    public static void main(String[] args) {
        IntBuffer intBuffer = IntBuffer.allocate(5);

        //向buffer 存放数据
        for (int i = 0; i < intBuffer.capacity(); i++) {
            intBuffer.put(i*2);
        }
        intBuffer.limit(4);
        //向buffer 取数据
        //将buffer转换，读写切换;
        intBuffer.flip();
        while (intBuffer.hasRemaining()){
            System.out.println(intBuffer.get());
        }


    }
}
